package day5;

import java.util.Scanner;

public class StudentManager {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入学生的数量：");
		int count = scanner.nextInt();
		Student[] students = new Student[count];
		for (int i = 0; i < students.length; i++) {
			System.out.println("请输入学生的id：");
			int id = scanner.nextInt();
			System.out.println("请输入学生的名字：");
			scanner.nextLine();// 先处理缓冲区里的内容
			String name = scanner.nextLine();
			System.out.println("请输入学生的年龄：");
			int age = scanner.nextInt();
			System.out.println("请输入学生的性别：");
			String gender = scanner.next();
			
			Student student = new Student(id, name, age, gender);
			students[i] = student;
		}
		System.out.println("----------------------------------------");
		while(true) {
			System.out.println("根据id来搜索：1");
			System.out.println("根据name来搜索：2");
			System.out.println("根据age来搜索：3");
			System.out.println("根据gender来搜索：4");
			System.out.println("退出：0");
			int type = scanner.nextInt();
			if (type == 0) {
				break;
			}
			switch (type){
			case 1:
				System.out.println("请输入查询学生的id：");
				int id = scanner.nextInt();
				boolean isfoundid = false;
				for (int i = 0; i < students.length; i++) {
					if (students[i].getId() == id) {
						System.out.println(students[i]);
						isfoundid = true;
					}
				}
				if (isfoundid == false) {
					System.out.println("未找到该学生");
				}
				break;
			case 2:
				System.out.println("请输入查询学生的名字：");
				boolean isfoundname = false;
				String name = scanner.next();
				for (int i = 0; i < students.length; i++) {
					if (students[i].getName() == name) {
						System.out.println(students[i]);
						isfoundname = true;
					}
				}
				if (isfoundname == false) {
					System.out.println("未找到该学生");
				}
				break;
			case 3:
				System.out.println("请输入查询学生的年龄：");
				boolean isfoundage = false;
				int age = scanner.nextInt();
				for (int i = 0; i < students.length; i++) {
					if (students[i].getAge() == age) {
						System.out.println(students[i]);
						isfoundage = true;
					}
				}
				if (isfoundage == false) {
					System.out.println("未找到该学生");
				}
				break;
			case 4:
				System.out.println("请输入查询学生的性别：");
				boolean isfoundgender = false;
				String gender = scanner.next();
				for (int i = 0; i < students.length; i++) {
					if (students[i].getGender() == gender) {
						System.out.println(students[i]);
						isfoundgender = true;
					}
				}
				if (isfoundgender == false) {
					System.out.println("未找到该学生");
				}
				break;
			}
		}
	}
}
